<template>
<!--  <h2>年检材料上报</h2>-->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch">
      <el-form-item label="单位名称" prop="registeredUnit">
        <el-input v-model="queryParams.registeredUnit" placeholder="请输入单位名称" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="年度" prop="year">
        <el-date-picker v-model="queryParams.year" type="year" placeholder="选择年"  format="yyyy" value-format="yyyy" style="width: 240px"></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择" clearable>
          <el-option v-for="item in dict.type.STATE" :key="item.value" :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8" ref="refbut">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="table" border v-loading="loading" :data="dataList" :height="tableHeight" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" :index="table_index" width="55" align="center" prop="id"/>
      <el-table-column label="标题" prop="title" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="年度" prop="year" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="下发单位" prop="registeredUnit" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="截止时间" prop="deadline" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="状态" prop="state" align="center">
        <template slot-scope="scope">
          <span v-for="(i, idx) in dict.type.STATE" :key="idx">
            {{ scope.row.state == i.value ? i.label : '' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="500">
        <template slot-scope="scope">
          <el-button type="success" plain @click="viewNotice(scope.row)">查看通知</el-button>
          <el-button type="warning" plain @click="selfTest(scope.row, 0)" v-show="scope.row.state=='1'">自检</el-button>
          <el-button type="warning" plain @click="selfTest(scope.row, 1)" v-show="scope.row.state=='3'">修改自检</el-button>
          <el-button type="danger" plain @click="viewReturn(scope.row)" v-show="scope.row.state=='3'">查看退回原因</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 查看通知 -->
    <Notice v-if="noticeOpen" :title="noticeTitle" :open="noticeOpen" @closeDelDialog="closeDelDialog" :dataInfo="dataInfo" :showDelete="false"></Notice>

    <!-- 自检 -->
    <SelfTest :title="testTitle" :open="testOpen" @closeDelDialog="closeDelDialog" :dataInfo="dataInfo" :showDelete="true"></SelfTest>

    <!-- 退回 -->
    <Return :title="returnTitle" :open="returnOpen" @closeDelDialog="closeDelDialog" :dataInfo="dataInfo" :showDelete="false"></Return>
  </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";
import SelfTest from "@/views/archive/supervision/materialReportingNb/selfTest";
import Return from "@/views/archive/supervision/materialReporting/return";
import Notice from "@/views/archive/supervision/annualInspectionNotice/notice";
import {findNotice, getReportList} from "@/api/archive/supervision/materialReporting";

export default {
  name: "index",
  components: { Return, SelfTest, Notice },
  mixins: [estimateTableHeight], // 混入方法
  archive_Dicts: [ 'STATE'],
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        materialState: 1,
        deptName: "",
        year: "",
        state: "",
        registeredUnit:"",
        type:"nb"
      },
      loading: true,
      dataList: [],
      total: 0,
      showSearch: true,
      testTitle: '',
      testOpen: false,
      returnTitle: '',
      returnOpen: false,
      noticeTitle: '',
      noticeOpen: false,
      dataInfo: {}
    }
  },
  created() {
    this.getList()

  },
  methods: {
    table_index(index){
      return (this.queryParams.pageNum-1) * this.queryParams.pageSize + index + 1;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    getList() {
      this.loading = true
      getReportList(this.queryParams).then(res=>{
        this.dataList = res.rows
        this.loading = false
        this.total = res.total
      })
    },
    // 查看通知
    viewNotice(row) {
      findNotice({id: row.id}).then(response=>{
        this.noticeTitle = '查看年检通知'
        this.noticeOpen = true
        this.$nextTick(() => {
          if (response.data != undefined) {
            this.dataInfo = response.data
          }
        })
      })
    },
    viewReturn(row) {
      findNotice({id: row.id}).then(response=>{
        if (response.data != undefined) {
          this.dataInfo = response.data
        }
        this.returnTitle = '查看退回原因'
        this.returnOpen = true
      })
    },
    selfTest(row, e) {
      findNotice({id: row.id}).then(response=>{
        if (response.data != undefined) {
          this.dataInfo = response.data
        }
        if (e == 0) {
          this.testTitle = '年报材料填写'
        } else {
          this.testTitle = '年报材料修改'
        }
        this.testOpen = true
      })
    },
    closeDelDialog() {
      this.testOpen = false
      this.returnOpen = false
      this.noticeOpen = false
      this.getList()
    }
  }
}
</script>

<style scoped>

</style>
